#!/usr/bin/env python
# -*- coding: utf-8 -*-


import requests
import re
import sys


from json_parse import Jsonparse

description = 'jboss (CVE-2017-12149)'


headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0",
    "Accept-Charset": "GBK,utf-8;q=0.7,*;q=0.3",
    "Content-Type": "text/xml"
}


class JbossScanner(object):
    def __init__(self,ip,port,level):
        self.ip = ip
        self.port = port
        self.level = level
    def run(self):
        tg = 'http://'+self.ip+':'+str(self.port)
        url= tg +'/invoker/readonly'
        try:
            response = requests.get(url, verify=False, timeout=self.level, headers=headers)
            status = response.status_code
            if status==500 and "JBoss" in response.text:
                print("successful")
                exit(233)
            else:
                print("false")
                exit(1)
        except Exception as e:
            print(e)
            exit(-1)

if __name__ == '__main__':
    jsonfile = sys.argv[1] + '\\poc\\lib\\config.json'
    jsonobj = Jsonparse(jsonfile)
    jsondata = jsonobj.parse()
    targetip = sys.argv[2]
    timeout = jsondata['timeout']
    port = sys.argv[3]
    Scanner = JbossScanner(targetip, int(port), timeout)
    Scanner.run()
